using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_ShopUploadFile : Admin, IRequiresSessionState
{
	protected DropDownList DropUploadFileType;
	protected TextBox UpTime;
	protected Button Button1;
	protected GridView GridView1;
	protected int nPage = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(24))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "UploadFile");
			base.WriteRightErrMsg();
		}
		if (!base.IsPostBack)
		{
			this.UpTime.Attributes.Add("onClick", string.Concat(new string[]
			{
				"show_cele_date(",
				this.UpTime.UniqueID,
				",'','',",
				this.UpTime.UniqueID,
				");"
			}));
			this.BandDLUploadFile();
		}
	}
	private void BandDLUploadFile()
	{
		PagedDataSource pagedDataSource = new PagedDataSource();
		DataTable dataSource = new DataTable();
		string str = "";
		string text = this.DropUploadFileType.SelectedValue.Trim();
		if (text != null)
		{
			if (!(text == "0"))
			{
				if (!(text == "1"))
				{
					if (!(text == "2"))
					{
					}
				}
				else
				{
					if (this.UpTime.Text != "")
					{
						try
						{
							str = "/" + DateTime.Parse(this.UpTime.Text).ToString("yyyyMM");
						}
						catch
						{
						}
					}
					dataSource = this.GetFileList("ShopPic" + str);
				}
			}
		}
		this.GridView1.DataSource = dataSource;
		this.GridView1.DataBind();
	}
	protected void DropUploadFileType_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.BandDLUploadFile();
	}
	protected void TxtNickName_TextChanged(object sender, EventArgs e)
	{
		this.BandDLUploadFile();
	}
	protected void DropIdentity_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.BandDLUploadFile();
	}
	protected void TxtUploadFile_TextChanged(object sender, EventArgs e)
	{
		this.BandDLUploadFile();
	}
	protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BandDLUploadFile();
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(24))
		{
			base.WriteRightErrMsg();
		}
		string toolTip = ((CheckBox)this.GridView1.SelectedRow.Cells[0].FindControl("sele")).ToolTip;
		bool flag = this.DeleteFile(toolTip);
		if (flag)
		{
			this.BandDLUploadFile();
		}
		else
		{
			MessageBox.Show(this, "删除失败，可能没有删除权限！");
		}
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			HyperLink hyperLink = (HyperLink)gridViewRow.FindControl("HLView");
			HyperLink expr_37 = hyperLink;
			string navigateUrl = expr_37.NavigateUrl;
			expr_37.NavigateUrl = string.Concat(new string[]
			{
				navigateUrl,
				"&id=",
				gridViewRow.Cells[0].Text,
				"&type=",
				this.DropUploadFileType.SelectedValue.Trim()
			});
		}
	}
	protected DataTable GetFileList(string DriectoryName)
	{
		DataTable dataTable = new DataTable();
		dataTable.Columns.Add("Name");
		dataTable.Columns.Add("imageurl");
		dataTable.Columns.Add("Type");
		dataTable.Columns.Add("Size");
		dataTable.Columns.Add("UpdateTime");
		string path = HttpContext.Current.Server.MapPath("..") + "/Shop/UploadFile/" + DriectoryName;
		DirectoryInfo directoryInfo = new DirectoryInfo(path);
		if (directoryInfo.Exists)
		{
			FileInfo[] files = directoryInfo.GetFiles();
			for (int i = 0; i < files.Length; i++)
			{
				FileInfo fileInfo = files[i];
				int num = this.SelectBDPic(DriectoryName + "/" + fileInfo.Name);
				if (num <= 0)
				{
					DataRow dataRow = dataTable.NewRow();
					dataRow["imageurl"] = "Shop/UploadFile/" + DriectoryName + "/" + fileInfo.Name;
					dataRow["Name"] = fileInfo.Name;
					dataRow["Type"] = fileInfo.Extension.Replace(".", "");
					dataRow["Size"] = 1000;
					dataRow["UpdateTime"] = fileInfo.LastWriteTime.ToString();
					dataTable.Rows.Add(dataRow);
				}
			}
		}
		return dataTable;
	}
	protected bool DeleteFile(string filepath)
	{
		string fileName = HttpContext.Current.Server.MapPath("..") + "/" + filepath;
		FileInfo fileInfo = new FileInfo(fileName);
		bool result;
		if (fileInfo.Exists)
		{
			try
			{
				fileInfo.Delete();
				result = true;
				return result;
			}
			catch
			{
				result = false;
				return result;
			}
		}
		result = false;
		return result;
	}
	protected int SelectBDPic(string DriectoryName)
	{
		string text = DriectoryName.Split(new char[]
		{
			'/'
		})[0];
		int result;
		if (text != null)
		{
			if (text == "IDCardPic")
			{
				result = 1;
				return result;
			}
			if (text == "ShopPic")
			{
				Shop_Product shop_Product = new Shop_Product();
				result = shop_Product.GetProductByUploadPic("UploadFile/" + DriectoryName);
				return result;
			}
			if (text == "ShopLogo")
			{
				result = 1;
				return result;
			}
		}
		result = 1;
		return result;
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		this.BandDLUploadFile();
	}
}
